﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
using DG.Tweening;

public class GameManager : MonoBehaviour
{
    public static GameManager instance = null;
    public GameObject bg;
    GameObject images;
    public Transform topImages;

    //公共参数
    public static bool b_ismax = false;                 //当前有图片展示
    public static GROUP group = GROUP.None;             //当前展示第几组
    public static bool b_isani = false;                 //当前是否有展示图片动画

    public static float f_daijiani = 1.5f;              //待机动画展示素的
    public static Tweener T_daijiTweener;               //正在进行的待机动画

    public void Awake()
    {
        //Cursor.visible = false;
        instance = this;
    }

    public void FixedUpdate()
    {
        TimerMngr.Instance.FixedUpdate();
    }

    // Use this for initialization
    void Start()
    {
        images = GameObject.Find("Images");
        topImages = GameObject.Find("Tops").transform;
        OperatingAll();
    }

    public void OperatingImage(string imageName)
    {
        Transform image = images.transform.FindChild(imageName);
        if (image == null)
            return;
        if(topImages.childCount == 0)
        {
            image.parent = topImages;
            image.SetPosZ(-1);
        }
        else
        {
            Transform topimage = topImages.GetChild(0);
            topimage.SetPosZ(0);
            image.SetPosZ(-1);
            topimage.parent = images.transform;
            image.parent = topImages;
        }
        
    }
    
    /// <summary>
    /// 操作ui
    /// </summary>
    public void OperatingAll()
    {
        StartCoroutine("Opendaiji");
    }
    IEnumerator Opendaiji()
    {
        if (bg.activeSelf) yield break;
        yield return new WaitForSeconds(10);
        bg.transform.parent.gameObject.SetActive(true);
        bg.SetActive(true);
        T_daijiTweener = bg.GetComponent<Image>().DOColor(new Color(1, 1, 1, 1), 1.5f);
    }

    public void CloseIenumerator()
    {
        bg.transform.parent.gameObject.SetActive(false);
        bg.SetActive(false);
        bg.GetComponent<Image>().color = new Color(1, 1, 1, 0);
        StopCoroutine("Opendaiji");
        if (T_daijiTweener!=null && T_daijiTweener.IsPlaying())
        {
            T_daijiTweener.OnComplete<Tweener>(() => { bg.GetComponent<Image>().color = new Color(1, 1, 1, 0); });
        }
    }
}

public enum GROUP
{
    None = 0,
    Image1 = 1,
    Image2 = 2,
    Image3 = 3,
    Image4 = 4,
    ALL = 5
}
